"""Rendering different XML-format views of metadata for datasets"""
"""Uses the duetopia.metadata libraries heavily"""

from duetopia.metadata.iso19115 import ISO19115
from duetopia.metadata.rdf import RDF 

from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import get_object_or_404
from duetopia.register.models.dataset import DataSet

__all__ = ("view_iso19115","view_rdf")

def view_iso19115(request,pk=None):
    return view_xml(ISO19115(),pk)

def view_rdf(request,pk=None):
    return view_xml(RDF(),pk)

def view_xml(md, pk=None):
    ds = get_object_or_404(DataSet,pk=pk)
    md.dataset = ds
    md.agent = ds.contacts
    md.timespan = ds.timespan
    xml = md.export()
    return HttpResponse(content=xml,content_type='text/xml')
    

